package huang.homework16;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MenuDao {
	BaseDao bd=new BaseDao();
	Connection con=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	//关闭数据库
	 void close() throws SQLException{
		if(rs!=null){
			rs.close();
		}
		if(ps!=null){
			ps.close();
		}
		if(con!=null){
			con.close();
		}
	}
	//查新数据库menu通过类别；
	 public List<Menu> selectMenuByType(String type) throws SQLException{
		 con=bd.getCon();
		 String sql="select * from menu where type=?";
		 ps=con.prepareStatement(sql);
		 ps.setString(1, type);
		 rs=ps.executeQuery();
		 int id=0;
		 String name=null;
		 float price=0f;
		 String information=null;
		 String type1=null;
		 List<Menu> mList=new ArrayList<Menu>();
		 while(rs.next()){
			 id=rs.getInt("id");
			 name=rs.getString("name");
			 price=rs.getFloat("price");
			 information=rs.getString("information");
			 type1=rs.getString("type");
			 Menu menu=new Menu(id,name,price,information,type1);
			 mList.add(menu);
		 }
		 return mList;
	 }
}
